package com.ict.txmsv2.controller.members;

import com.ict.txmsv2.model.MethodDescrition;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.model.RespPageBean;
import com.ict.txmsv2.model.User;
import com.ict.txmsv2.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yoleen
 * @date 2020/12/16 18:47
 */

@RestController
@RequestMapping("/members/detail")
public class DetailController {
    @Autowired
    UserService userService;

    @GetMapping("/")
    @MethodDescrition("分页查询成员信息")
    public RespPageBean getDetail(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer size,
                                 String name, String dept, String major, String beginTime, String endTime){
        return userService.getDetail(page, size, name, dept, major, beginTime, endTime);
    }

    @PutMapping("/")
    @MethodDescrition("修改成员信息")
    public RespBean updateDetail(@RequestBody User user){
        if (userService.updateDetail(user)==1) {
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }

    @DeleteMapping("/{id}")
    @MethodDescrition("删除成员")
    public RespBean deleteDetail(@PathVariable int id) {
        if (userService.deleteDetail(id) == 1) {
            return RespBean.ok("删除咯");
        }
        return RespBean.error("系统想你留下来");
    }

    @DeleteMapping("/")
    @MethodDescrition("删除成员s")
    public RespBean deleteDetails(int[] ids) {
        if (userService.deleteDetails(ids) == ids.length) {
            return RespBean.ok("都删除咯");
        }
        return RespBean.error("系统想你们留下来");
    }
}
